package com.ruoyi.web.controller.talentServerController;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TalPolicy;
import com.ruoyi.system.service.ITalPolicyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人才政策Controller
 *
 * @author zhusq
 * @date 2023-03-27
 */
@RestController
@RequestMapping("/system/policy")
public class TalPolicyController extends BaseController
{
    @Autowired
    private ITalPolicyService talPolicyService;

    /**
     * 查询人才政策列表
     */
    @PreAuthorize("@ss.hasPermi('system:policy:list')")
    @GetMapping("/list")
    public TableDataInfo list(TalPolicy talPolicy)
    {
        startPage();
        List<TalPolicy> list = talPolicyService.selectTalPolicyList(talPolicy);
        return getDataTable(list);
    }

    /**
     * 导出人才政策列表
     */
    @PreAuthorize("@ss.hasPermi('system:policy:export')")
    @Log(title = "党员活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TalPolicy talPolicy)
    {
        List<TalPolicy> list = talPolicyService.selectTalPolicyList(talPolicy);
        ExcelUtil<TalPolicy> util = new ExcelUtil<TalPolicy>(TalPolicy.class);
        util.exportExcel(response, list, "党员活动数据");
    }

    /**
     * 获取人才政策详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:policy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(talPolicyService.selectTalPolicyById(id));
    }

    /**
     * 新增人才政策
     */
    @PreAuthorize("@ss.hasPermi('system:policy:add')")
    @Log(title = "人才政策", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TalPolicy talPolicy)
    {
        return toAjax(talPolicyService.insertTalPolicy(talPolicy));
    }

    /**
     * 修改人才政策
     */
    @PreAuthorize("@ss.hasPermi('system:policy:edit')")
    @Log(title = "党员活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TalPolicy talPolicy)
    {
        return toAjax(talPolicyService.updateTalPolicy(talPolicy));
    }

    /**
     * 删除人才政策
     */
    @PreAuthorize("@ss.hasPermi('system:policy:remove')")
    @Log(title = "党员活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(talPolicyService.deleteTalPolicyByIds(ids));
    }
}
